﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AppServidor
{
    public partial class Bitacora_Server : Form
    {
       public  Server server;
       Thread leer_bitacora;
        bool monitorear=true;
        public Bitacora_Server()
       {
           CheckForIllegalCrossThreadCalls = false;
           leer_bitacora = new Thread(new ThreadStart(leer_del_server));
            InitializeComponent();
        }

      
        public void iniciar() { 
        monitorear=true;
        leer_bitacora.Start();
        
        }
        public void stop()
        {
            monitorear =false;
            

        }

        private void leer_del_server() {
            while (monitorear&&server!=null) {
                List<string> listas = server.incidentes;
                this.listBox1.Items.Clear();
                foreach (string aux in listas)
                    this.listBox1.Items.Add(aux);
                Thread.Sleep(2000);
            }
        }
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (server != null) {
                int i = listBox1.SelectedIndex;
                if(i>=0&&i<server.bitacora.Count)
                MessageBox.Show(server.bitacora[i]);
            }
        }

        private void Bitacora_Server_FormClosing(object sender, FormClosingEventArgs e)
        {
            stop();
        }
    }
}
